package com.xigua._查找;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/2/1510:49
 */
public class _1380_矩阵中的幸运数 {

    public static void main(String[] args) {

    }

    public List<Integer> luckyNumbers (int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] minRow = new int[m];
        Arrays.fill(minRow,Integer.MAX_VALUE);
        int[] maxCol = new int[n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                minRow[i] =Math.min(minRow[i],matrix[i][j]);
                maxCol[j] = Math.max(maxCol[j],matrix[i][j]);
            }
        }
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (matrix[i][j] == minRow[i] && matrix[i][j] == maxCol[j]){
                    ans.add(matrix[i][j]);
                }
            }
        }

        return ans;
    }

}
